<template>
  <view id="scrollBox" class="assessList">
    <view class="talkBox marginTop24">
      <view class="talkRow talkLeft">
        <view class="talk">
          <img :src="require('../images/icons/whlogo.png')" />
          <view v-if="loadingImg" class="loadingBox">
            <view class="pulse-container">
              <view class="pulse-bubble pulse-bubble-1"></view>
              <view class="pulse-bubble pulse-bubble-2"></view>
              <view class="pulse-bubble pulse-bubble-3"></view>
            </view>
          </view>
          <view v-else class="txt">您好，我是智能健康管家小万宝。我有很多身体健康程度的评估方法，请根据需要选择：</view>
        </view>
      </view>
      <view v-if="!curAssTypeName && !loadingImg" class="talkRow talkRight">
        <view class="talk">
          <view v-for="item in assList" :key="item.id" class="txt">
            <span @click="choseAssType(item)">{{ item.name }}</span>
          </view>
        </view>
      </view>
      <view v-if="curAssTypeName" class="talkRow talkRight answer">
        <view class="talk talkUser">
          <view class="headImg"><img :src="headImg" /></view>
          <view class="txt noBorder">
            <span>{{ curAssTypeName }}</span>
          </view>
        </view>
      </view>
    </view>
    <view class="getAssHeight">
      <cardiovascularPage
        v-if="curAssTypeName"
        :patientId="patientId"
        :optionRelation="optionRelation"
        :optionSex="optionSex"
      ></cardiovascularPage>
    </view>
  </view>
</template>

<script>
import cardiovascularPage from './cardiovascularPage';
// 家人关系
export default {
  components: {
    cardiovascularPage
  },
  data() {
    return {
      assList: [
        { name: '综合健康评估', id: 1 },
        { name: '心脑血管风险评估', id: 2 }
      ],
      curAssTypeName: '',
      patientId: '',
      optionSex: '',
      optionRelation: '',
      man:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/man.png',
      woman:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/woman.png',
      son:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/son.png',
      father:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/father.png',
      der:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/der.png',
      mother:
        'https://wanhuhealth.oss-cn-beijing.aliyuncs.com/wanhuhealth-small-program/wanhu-mini-welfare/welfare/index/mother.png',
      headImg: '',
      loadingImg: true
    };
  },

  computed: {
    // 计算体型
  },
  onLoad: function (option) {
    if (option && option.patientId) {
      this.patientId = option.patientId;
      this.optionSex = Number(option.sex) || '';
      this.optionRelation = Number(option.relation) || '';
    } else {
      // patientId=29dc1b31e8f04eee87cedf8bb8b9817e&id=60b0469968c137567cf19661
    }
    this.headImg = this.headImgFilter();
    const self = this;
    setTimeout(function () {
      self.loadingImg = false;
    }, 1000);
  },
  methods: {
    choseAssType(item) {
      if (item.id === 1) {
        this.$wxPromise.navigateTo({
          url: '/pagesB/assessSick/index?patientId=' + this.patientId
        });
      } else {
        this.curAssTypeName = item.name;
      }
    },
    headImgFilter() {
      let src;
      if (this.optionSex === 1) {
        // 只有父母和子女需要区分性别
        if (this.optionRelation === 3) {
          src = this.father;
        } else if (this.optionRelation === 4) {
          src = this.son;
        } else {
          src = this.man;
        }
      } else {
        if (this.optionRelation === 3) {
          src = this.mother;
        } else if (this.optionRelation === 4) {
          src = this.der;
        } else {
          src = this.woman;
        }
      }
      // 如果是本人的话，则使用微信头像
      if (this.optionRelation === 1) {
        this.userInfo = JSON.parse(wx.getStorageSync('rawData'));
        src = this.userInfo.avatarUrl || this.man;
      }
      return src;
    }
  }
};
</script>
<style lang="scss">
@import './../style/assessList.scss';
</style>
